<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.cvicse.workflow.api.query.entity.*"%>

<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
	<head>
		<title>
			综合管理
		</title>
		<script language="javascript">
function increaseCondition(){
	document.fm.increase.value = "yes";
	document.fm.action="workflowmonitorhis.html?method=getRunningItem&type=3";
	document.fm.method="post";
	document.fm.submit();
}

function deleteCondition(num){
	document.fm.deleteId.value = num;
	document.fm.action="workflowmonitorhis.html?method=getRunningItem&type=3";
	document.fm.method="post";
	document.fm.submit();
}
</script>
		<link href="./monitor/css/index.css" rel="stylesheet" type="text/css">
	</head>
	<body bgcolor="#ffffff">
		<%
Map qtype = new HashMap();
qtype.put("3","工作项实例查询");
qtype.put("4","活动实例查询");
qtype.put("5","运行时流程查询");
String type = request.getParameter("type");
if(type == null) type = (String)request.getAttribute("type");
%>
	<h3 align="center">
		<%=(String)qtype.get(type)%>
	</h3>
	<center>
		在查询的可选属性中，acvitivtyId,processId,workItemId等必须输入整形; 如果没有填写任何条件，则返回所有结果。
		<form method="post" name="fm" id="fm" action='<%=request.getContextPath()%>/workflowmonitorhis.html?method=getRunningItem&type=3'>
			<%

List conditions = (List)request.getAttribute("conditions");
for(int i=0;i<conditions.size();i++){
	String c = (String)conditions.get(i);
	String item1,operator,item2,logic;
	if(c!=null && c.length() > 0){
		item1=c.substring("item1=".length(),c.indexOf(";operator"));
		operator=c.substring(c.indexOf("operator=")+"operator=".length(),
					c.indexOf(";item2"));
		item2=c.substring(c.indexOf("item2=")+"itme2=".length(),
					c.indexOf(";logic"));
		logic=c.substring(c.indexOf("logic=")+"logic=".length(),
					c.length()-1);
	}else{
		item1="";
		operator="";
		item2="";
		logic="";
	}
      %>
				<table cellpadding="0" cellspacing="0">
					<tr>
						<th>
							条件
							<%out.print(i+1);%>
							：
						</th>
						<th>
							<select name="item1<%=i%>">
								<%
            List entities = new ArrayList();
			List list = new ArrayList();
            switch (Integer.parseInt(type)){
            	case 3:
                	entities = RunningEntity.getEntities();
    	            for(int j = 0; j < entities.size(); j++){
    	            	Entity entity = (Entity)entities.get(j);
    	            	list.add(entity.getAttribute());
    	            	Collections.sort(list);
    	            }
    	            for(int h = 0; h < list.size(); h++){
                		out.print("<option value="+list.get(h) + (item1.equals(list.get(h))?" selected":"") + ">"+list.get(h) +"</option>");
    	            }
                break;
            	case 4:
                	entities = RunningEntity.getEntities();
    	            for(int j = 0; j < entities.size(); j++){
    	            	Entity entity = (Entity)entities.get(j);
    	            	list.add(entity.getAttribute());
    	            	Collections.sort(list);
    	            }
    	            for(int h = 0; h < list.size(); h++){
                		out.print("<option value="+list.get(h) + (item1.equals(list.get(h))?" selected":"") + ">"+list.get(h) +"</option>");
    	            }
                break;
            	case 5:
                	entities = RunningEntity.getEntities();
    	            for(int j = 0; j < entities.size(); j++){
    	            	Entity entity = (Entity)entities.get(j);
    	            	list.add(entity.getAttribute());
    	            	Collections.sort(list);
    	            }
    	            for(int h = 0; h < list.size(); h++){
                		out.print("<option value="+list.get(h) + (item1.equals(list.get(h))?" selected":"") + ">"+list.get(h) +"</option>");
    	            }
                break;
            	default:break;
            }
            %>
			</select>
			</th>
			<th>
				<select name="operator<%=i%>">
					<option value="=" <%="=".equals(operator)?"selected":""%>>
						等于
					</option>
					<option value="!=" <%="!=".equals(operator)?"selected":""%>>
						不等于
					</option>
					<option value="&lt;" <%="<".equals(operator)?"selected":""%>>
						小于
					</option>
					<option value="&lt;=" <%="<=".equals(operator)?"selected":""%>>
						小于等于
					</option>
					<option value="&gt;" <%=">".equals(operator)?"selected":""%>>
						大于
					</option>
					<option value="&gt;=" <%=">=".equals(operator)?"selected":""%>>
						大于等于
					</option>
					<option value="like" <%="like".equals(operator)?"selected":""%>>
						like
					</option>
					<option value="in" <%="in".equals(operator)?"selected":""%>>
						in
					</option>
	          </select>
	    </th>
        <th><input type="text" class = "intext" name="item2<%=i%>" value='<%=item2%>'></th>
        <th><select name="logic<%=i%>" id="logic<%=i%>">
            <option value="and" <%="and".equals(logic)?"selected":""%>>and</option>
            <option value="or" <%="or".equals(logic)?"selected":""%>>or</option>
          </select></th>
        <th><input type="button" onclick="deleteCondition('<%=i%>')" value="删除"></th>
      </tr>
      <%}%>
    </table>
<br>
<input type=button value=增加条件 name=inc onclick="increaseCondition()">
<input type=submit value=查询 name=sub >

<input type="hidden" name="deleteId" value="">
<input type="hidden" name="increase" value="">
<input type="hidden" name="type" value='<%=request.getParameter("type")%>'>
<input type="hidden" name="submited" value='<%=request.getParameter("permit")%>'>

	<table width="100%" cellpadding="0" cellspacing="0">
		<tr>
						<th nowrap>
						工作项号
						</th>
						<th nowrap>
							所属流程号
						</th>
						<th nowrap>
							所属活动号
						</th>
						<th nowrap>
							名称
						</th>
						<th nowrap>
							状态
						</th>
						<th nowrap>
							执行人
						</th>
						<th nowrap>相关数据</th>
						<th nowrap>操作</th>
						
		</tr>
					<%
						String tdClass = "";
						String thClass = "";
						List list = (List)request.getAttribute("workItemMaps");
						for(int k=0;k<list.size();k++) {
							Map attrs = (Map)list.get(k);
							if (k % 2 == 1) {
								tdClass = "class=alt";
								thClass = "class=specalt";
							} else {
								thClass = "class=spec";
								tdClass = "";
							}
					%>
		<tr>
			<td nowrap <%=tdClass%>><%=attrs.get("id")%>
			<td nowrap <%=tdClass%>><%=attrs.get("processInstanceId")%>
			<td nowrap <%=tdClass%>><%=attrs.get("activityInstanceId")%>
			<td nowrap <%=tdClass%>><%=attrs.get("name")%>
			<td nowrap <%=tdClass%>><%=attrs.get("state")%>
			<td nowrap <%=tdClass%>><%=attrs.get("participant")%>
			<td nowrap <%=tdClass%>><%=attrs.get("id")%>
			<td nowrap <%=tdClass%></td>
		
		</tr>
						<%}%>
	</table>

</body>
</html>

<SCRIPT LANGUAGE="JavaScript">
<!--
	function deleteProcess(id) {
		if (confirm("您确定删除该流程实例吗？"))
			location.href="workflowmonitor.html?method=deleteProcess&id="+id;
	}
//-->
</SCRIPT>